package com.lightjet.macross.base.feign.api.domain;

import io.netty.util.internal.StringUtil;
import lombok.Getter;
import lombok.Setter;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Arrays;
import java.util.Collection;
import java.util.stream.Collectors;

@Getter
@Setter
public class AuthUser implements UserDetails {

    String id;

    String username;

    String password;

    String displayname;

    String workno;

    String orgname;

    String orgid;

    String email;

    String unicode;

    String roles;

    String usibn;

    boolean accountNonExpired = true;

    boolean accountNonLocked = true;

    boolean credentialsNonExpired = true;

    boolean enabled = true;

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        if(!StringUtil.isNullOrEmpty(roles))
        {
            return Arrays.stream(roles.split(",")).map(AuthRole::new).collect(Collectors.toList());
            //new GrantedAuthority()
        }
        else
        {
            return null;
        }
    }

    @Override
    public String getPassword() {
        return password;
    }

    @Override
    public String getUsername() {
        return username;
    }

    @Override
    public boolean isAccountNonExpired() {
        return accountNonExpired;
    }

    @Override
    public boolean isAccountNonLocked() {
        return accountNonLocked;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return credentialsNonExpired;
    }

    @Override
    public boolean isEnabled() {
        return enabled;
    }
}
